packages = c('readxl', 'datawizard')
for(p in packages){
if(!require(p,character.only = T)){
install.packages(p)
}
library(p,character.only = T)
}Take-home Exercise 4
Putting Visual Analytics into Practical Use
1 The task
In this take-home exercise, you are required to uncover the impact of COVID-19 as well as the global economic and political dynamic in 2022 on Singapore bi-lateral trade (i.e. Import, Export and Trade Balance) by using appropriate analytical visualisation techniques learned in Lesson 6: It’s About Time. Students are encouraged to apply appropriate interactive techniques to enhance user and data discovery experiences.
The write-up of the take-home exercise should include but not limited to the followings:
- Describe the selection and designed consideration of the analytical data visualisation used. The discussion should limit to not more than 150 words each.
- A reproducible description of the procedures used to prepare the analytical visualisation. Please refer to the peer submission I shared.
- A write-up of not more than 100 words to discuss the patterns reveal by each analytical visualization prepared.
Packages
2 Data
For the purpose of this take-home exercise, Merchandise Trade provided by Department of Statistics, Singapore (DOS) will be used. The data are available under the sub-section of Merchandise Trade by Region/Market. You should download the data by clicking on the link Download all in Excel on the same webpage. The study period should be between January 2020 to December 2022.
Checking the number of sheets it contains
excel_sheets("data/data.xlsx")[1] "Content" "T1" "T2"
Importing data
T1 <- data_transpose(read_excel("data/data.xlsx", sheet = "T1"), rownames = "Month", colnames = TRUE)
T2 <- data_transpose(read_excel("data/data.xlsx", sheet = "T2"), rownames = "Month", colnames = TRUE)2.1 T1 table: Merchandise Imports By Region/Market, Monthly
Code
knitr::kable(
head(T1, 5))| Month | Total Merchandise Imports (Thousand Dollars) | America (Million Dollars) | Asia (Million Dollars) | Europe (Million Dollars) | Oceania (Million Dollars) | Africa (Million Dollars) | European Union (Million Dollars) | Belgium (Thousand Dollars) | Denmark (Thousand Dollars) | France (Thousand Dollars) | Germany, Federal Republic Of (Thousand Dollars) | Greece (Thousand Dollars) | Ireland (Thousand Dollars) | Italy (Thousand Dollars) | Luxembourg (Thousand Dollars) | Netherlands (Thousand Dollars) | United Kingdom (Thousand Dollars) | Portugal (Thousand Dollars) | Spain (Thousand Dollars) | Austria (Thousand Dollars) | Finland (Thousand Dollars) | Norway (Thousand Dollars) | Sweden (Thousand Dollars) | Switzerland (Thousand Dollars) | Liechtenstein (Thousand Dollars) | Malta (Thousand Dollars) | Germany, Democratic Republic Of (Thousand Dollars) | Hungary (Thousand Dollars) | Poland (Thousand Dollars) | Estonia (Thousand Dollars) | Latvia (Thousand Dollars) | Lithuania (Thousand Dollars) | Slovenia (Thousand Dollars) | Czech Republic (Thousand Dollars) | Slovak Republic (Slovakia) (Thousand Dollars) | Brunei Darussalam (Thousand Dollars) | Indonesia (Thousand Dollars) | Malaysia (Thousand Dollars) | Philippines (Thousand Dollars) | Thailand (Thousand Dollars) | Myanmar (Thousand Dollars) | Cambodia (Thousand Dollars) | Laos People’s Democratic Republic (Thousand Dollars) | Vietnam, Socialist Republic Of (Thousand Dollars) | Japan (Thousand Dollars) | Hong Kong (Thousand Dollars) | Republic Of Korea (Thousand Dollars) | Taiwan (Thousand Dollars) | Macau (Thousand Dollars) | Mainland China (Thousand Dollars) | Afghanistan (Thousand Dollars) | Bangladesh (Thousand Dollars) | India (Thousand Dollars) | Maldives, Republic Of (Thousand Dollars) | Nepal (Thousand Dollars) | Pakistan (Thousand Dollars) | Sri Lanka (Thousand Dollars) | Bahrain (Thousand Dollars) | Cyprus (Thousand Dollars) | Iran (Islamic Republic Of) (Thousand Dollars) | Israel (Thousand Dollars) | Jordan (Thousand Dollars) | Kuwait (Thousand Dollars) | Lebanon (Thousand Dollars) | Oman (Thousand Dollars) | Qatar (Thousand Dollars) | Saudi Arabia (Thousand Dollars) | Syrian Arab Republic (Thousand Dollars) | United Arab Emirates (Thousand Dollars) | Yemen (Thousand Dollars) | Yemen Democratic (Thousand Dollars) | Canada (Thousand Dollars) | Puerto Rico (Thousand Dollars) | United States (Thousand Dollars) | Argentina (Thousand Dollars) | Brazil (Thousand Dollars) | Chile (Thousand Dollars) | Colombia (Thousand Dollars) | Ecuador (Thousand Dollars) | Mexico (Thousand Dollars) | Paraguay (Thousand Dollars) | Peru (Thousand Dollars) | Uruguay (Thousand Dollars) | Venezuela (Thousand Dollars) | Netherlands Antilles (Thousand Dollars) | Panama (Thousand Dollars) | Bahamas (Thousand Dollars) | Bermuda (Thousand Dollars) | French Guiana (Thousand Dollars) | Grenada (Thousand Dollars) | Guatemala (Thousand Dollars) | Honduras (Thousand Dollars) | Jamaica (Thousand Dollars) | St Vincent & The Grenadines (Thousand Dollars) | Trinidad & Tobago (Thousand Dollars) | Anguilla (Thousand Dollars) | Other Countries In America (Thousand Dollars) | Australia (Thousand Dollars) | Fiji (Thousand Dollars) | Nauru (Thousand Dollars) | New Caledonia (Thousand Dollars) | New Zealand (Thousand Dollars) | Papua New Guinea (Thousand Dollars) | Cocos (Keeling) Islands (Thousand Dollars) | French Southern Territories (Thousand Dollars) | Norfolk Island (Thousand Dollars) | Cook Islands (Thousand Dollars) | French Polynesia (Thousand Dollars) | Guam (Thousand Dollars) | Kiribati (Thousand Dollars) | Niue (Thousand Dollars) | Solomon Islands (Thousand Dollars) | Tuvalu (Thousand Dollars) | Wallis & Fatuna Islands (Thousand Dollars) | Micronesia (Thousand Dollars) | Palau (Thousand Dollars) | South Sudan (Thousand Dollars) | Other Countries In Oceania (Thousand Dollars) | Commonwealth Of Independent States (Thousand Dollars) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022 Dec | 49869770.0 | 6901.5 | 33611.7 | 7541.8 | 1399.9 | 414.9 | 5058.8 | 103655.0 | 67665.0 | 1537347.0 | 1129542.0 | 99085.0 | 106678.0 | 702472.0 | 8156.0 | 384010.0 | 940088.0 | 31026.0 | 262629.0 | 104665.0 | 42399.0 | 50581.0 | 162253.0 | 992687.0 | 2250.0 | 41040.0 | 0.0 | 44406.0 | 61324.0 | 5378.0 | 4288.0 | 13594.0 | 7106.0 | 69549.0 | 9115.0 | 143124.0 | 2074781.0 | 6017970.0 | 592778.0 | 1116398.0 | 7486.0 | 25899.0 | 7281.0 | 567388.0 | 2618288.0 | 240017.0 | 3207322.0 | 5357878.0 | 1376.0 | 7642587.0 | 61.0 | 27270.0 | 834657.0 | 103.0 | 221.0 | 7334.0 | 10737.0 | 44949.0 | 21698.0 | 317.0 | 98717.0 | 8265.0 | 639.0 | 332.0 | 72624.0 | 640131.0 | 801168.0 | 0.0 | 1212293.0 | 629.0 | 0.0 | 211232.0 | 8375.0 | 5314219.0 | 11273.0 | 1004171.0 | 16649.0 | 7915.0 | 4475.0 | 277739.0 | 681.0 | 3464.0 | 635.0 | 89.0 | 0.0 | 127.0 | 11.0 | 0.0 | 123.0 | 6.0 | 570.0 | 1457.0 | 93.0 | 0.0 | 64.0 | 0.0 | 37931.0 | 1253373.0 | 243.0 | 14.0 | 18.0 | 122266.0 | 23124.0 | 2.0 | 46.0 | 1.0 | 0.0 | 210.0 | 35.0 | 0.0 | 80.0 | 3.0 | 0.0 | 0.0 | 29.0 | 1.0 | 33107.0 | 1577.0 | 559381.0 |
| 2022 Nov | 50653907.0 | 7529.4 | 34733.7 | 7242.8 | 664.4 | 483.6 | 4961.4 | 121773.0 | 67436.0 | 1563127.0 | 1107630.0 | 37937.0 | 118525.0 | 725004.0 | 5714.0 | 301384.0 | 1050419.0 | 33086.0 | 245875.0 | 105084.0 | 49148.0 | 43134.0 | 196484.0 | 949410.0 | 3686.0 | 23080.0 | 0.0 | 46849.0 | 59504.0 | 6972.0 | 6436.0 | 8716.0 | 8502.0 | 77729.0 | 7487.0 | 121051.0 | 1971918.0 | 6773423.0 | 581054.0 | 1241990.0 | 6044.0 | 16407.0 | 4963.0 | 488956.0 | 2837697.0 | 169227.0 | 2863026.0 | 5319407.0 | 17054.0 | 8285837.0 | 26.0 | 25709.0 | 837673.0 | 145.0 | 612.0 | 10169.0 | 12169.0 | 11520.0 | 2385.0 | 267.0 | 85965.0 | 7262.0 | 54562.0 | 578.0 | 60005.0 | 476149.0 | 866619.0 | 0.0 | 1205738.0 | 106.0 | 0.0 | 224872.0 | 16518.0 | 5832049.0 | 6775.0 | 1132945.0 | 13831.0 | 4436.0 | 2745.0 | 242881.0 | 281.0 | 2155.0 | 779.0 | 720.0 | 0.0 | 116.0 | 4.0 | 4.0 | 517.0 | 19.0 | 997.0 | 838.0 | 117.0 | 0.0 | 2854.0 | 0.0 | 43918.0 | 577829.0 | 191.0 | 0.0 | 256.0 | 72677.0 | 12724.0 | 0.0 | 99.0 | 0.0 | 0.0 | 35.0 | 104.0 | 3.0 | 0.0 | 13.0 | 0.0 | 0.0 | 8.0 | 0.0 | 27952.0 | 3090.0 | 355213.0 |
| 2022 Oct | 53182943.0 | 7666.4 | 36120.9 | 7475.9 | 1329.8 | 589.9 | 4685.2 | 88796.0 | 63719.0 | 1493161.0 | 1122251.0 | 15850.0 | 157648.0 | 594994.0 | 15746.0 | 263199.0 | 859994.0 | 39971.0 | 184146.0 | 101231.0 | 49749.0 | 40090.0 | 180230.0 | 1811943.0 | 2650.0 | 51734.0 | 0.0 | 42761.0 | 72936.0 | 5489.0 | 2299.0 | 5892.0 | 8759.0 | 78066.0 | 9522.0 | 214994.0 | 1987191.0 | 6417377.0 | 646820.0 | 1431165.0 | 5856.0 | 9089.0 | 16907.0 | 522441.0 | 3038903.0 | 207166.0 | 3044583.0 | 6484560.0 | 2341.0 | 7377473.0 | 9.0 | 18536.0 | 826855.0 | 14.0 | 688.0 | 6327.0 | 14721.0 | 66675.0 | 2034.0 | 692.0 | 93452.0 | 3020.0 | 52798.0 | 449.0 | 108470.0 | 528921.0 | 1010564.0 | 3.0 | 1642118.0 | 265.0 | 0.0 | 213606.0 | 5480.0 | 6163496.0 | 14908.0 | 917460.0 | 11567.0 | 2200.0 | 4893.0 | 272680.0 | 487.0 | 11670.0 | 1123.0 | 885.0 | 0.0 | 175.0 | 4.0 | 0.0 | 12899.0 | 1.0 | 262.0 | 706.0 | 61.0 | 2.0 | 31.0 | 1.0 | 44771.0 | 1246296.0 | 170.0 | 0.0 | 14.0 | 72719.0 | 10221.0 | 2.0 | 115.0 | 0.0 | 0.0 | 60.0 | 65.0 | 0.0 | 1.0 | 21.0 | 1.0 | 0.0 | 5.0 | 0.0 | 0.0 | 269.0 | 211147.0 |
| 2022 Sep | 55799312.0 | 7995.9 | 37696.3 | 8167.6 | 1544.6 | 395.0 | 5145.8 | 215978.0 | 61842.0 | 1660563.0 | 1170472.0 | 107888.0 | 118936.0 | 547587.0 | 55482.0 | 314814.0 | 1131385.0 | 47500.0 | 209987.0 | 130438.0 | 48419.0 | 41524.0 | 143127.0 | 1758858.0 | 3558.0 | 23836.0 | 0.0 | 38367.0 | 82610.0 | 7789.0 | 2679.0 | 8406.0 | 7816.0 | 73954.0 | 7399.0 | 208537.0 | 1924895.0 | 7672003.0 | 599147.0 | 1343781.0 | 6949.0 | 12607.0 | 20214.0 | 594893.0 | 3109529.0 | 354257.0 | 3113799.0 | 5683947.0 | 436.0 | 7390866.0 | 19.0 | 18308.0 | 1023746.0 | 43.0 | 602.0 | 5272.0 | 13436.0 | 2744.0 | 1662.0 | 258.0 | 143055.0 | 8904.0 | 16848.0 | 303.0 | 42137.0 | 766915.0 | 954922.0 | 17.0 | 2315066.0 | 48.0 | 0.0 | 241035.0 | 9831.0 | 6537215.0 | 13163.0 | 833293.0 | 29599.0 | 10518.0 | 2522.0 | 263872.0 | 235.0 | 14741.0 | 3311.0 | 238.0 | 0.0 | 328.0 | 4.0 | 3.0 | 296.0 | 3.0 | 926.0 | 432.0 | 493.0 | 21.0 | 58.0 | 0.0 | 35101.0 | 1447901.0 | 498.0 | 8.0 | 262.0 | 79919.0 | 14332.0 | 0.0 | 242.0 | 0.0 | 23.0 | 37.0 | 176.0 | 0.0 | 3.0 | 4.0 | 0.0 | 0.0 | 10.0 | 0.0 | 14777.0 | 664.0 | 192289.0 |
| 2022 Aug | 58466009.0 | 8633.8 | 40911.9 | 7433.2 | 935.9 | 551.2 | 5131.0 | 132917.0 | 126150.0 | 1624646.0 | 1135242.0 | 170197.0 | 193225.0 | 592000.0 | 31284.0 | 339001.0 | 753406.0 | 45507.0 | 200170.0 | 105197.0 | 38114.0 | 36231.0 | 107557.0 | 1420434.0 | 3380.0 | 40703.0 | 0.0 | 39917.0 | 64268.0 | 7588.0 | 3549.0 | 6345.0 | 7957.0 | 76026.0 | 10549.0 | 311958.0 | 2301232.0 | 7225607.0 | 1121526.0 | 1511871.0 | 8313.0 | 21829.0 | 36150.0 | 688285.0 | 3100676.0 | 319470.0 | 3841813.0 | 7174679.0 | 3219.0 | 8196629.0 | 107.0 | 36996.0 | 908131.0 | 37.0 | 559.0 | 9692.0 | 12789.0 | 7085.0 | 2499.0 | 255.0 | 126174.0 | 3782.0 | 56351.0 | 337.0 | 73156.0 | 827737.0 | 1081996.0 | 0.0 | 1629843.0 | 151.0 | 0.0 | 599499.0 | 14898.0 | 6575058.0 | 11801.0 | 968690.0 | 75458.0 | 9806.0 | 1931.0 | 247995.0 | 513.0 | 1888.0 | 806.0 | 803.0 | 0.0 | 424.0 | 0.0 | 2.0 | 431.0 | 8.0 | 2170.0 | 793.0 | 137.0 | 0.0 | 80568.0 | 9.0 | 40996.0 | 696980.0 | 185.0 | 0.0 | 186.0 | 133089.0 | 104656.0 | 7.0 | 8.0 | 101.0 | 0.0 | 38.0 | 86.0 | 0.0 | 0.0 | 2.0 | 0.0 | 0.0 | 10.0 | 6.0 | 0.0 | 441.0 | 170747.0 |
2.2 T2 table: Merchandise Exports By Region/Market, Monthly
Code
knitr::kable(
head(T2, 5))| Month | Total Merchandise Exports (Thousand Dollars) | America (Million Dollars) | Asia (Million Dollars) | Europe (Million Dollars) | Oceania (Million Dollars) | Africa (Million Dollars) | European Union (Million Dollars) | Belgium (Thousand Dollars) | Denmark (Thousand Dollars) | France (Thousand Dollars) | Germany, Federal Republic Of (Thousand Dollars) | Greece (Thousand Dollars) | Ireland (Thousand Dollars) | Italy (Thousand Dollars) | Luxembourg (Thousand Dollars) | Netherlands (Thousand Dollars) | United Kingdom (Thousand Dollars) | Portugal (Thousand Dollars) | Spain (Thousand Dollars) | Austria (Thousand Dollars) | Finland (Thousand Dollars) | Sweden (Thousand Dollars) | Switzerland (Thousand Dollars) | Malta (Thousand Dollars) | Germany, Democratic Republic Of (Thousand Dollars) | Hungary (Thousand Dollars) | Poland (Thousand Dollars) | Estonia (Thousand Dollars) | Latvia (Thousand Dollars) | Lithuania (Thousand Dollars) | Slovenia (Thousand Dollars) | Czech Republic (Thousand Dollars) | Slovak Republic (Slovakia) (Thousand Dollars) | Brunei Darussalam (Thousand Dollars) | Indonesia (Thousand Dollars) | Malaysia (Thousand Dollars) | Philippines (Thousand Dollars) | Thailand (Thousand Dollars) | Myanmar (Thousand Dollars) | Cambodia (Thousand Dollars) | Laos People’s Democratic Republic (Thousand Dollars) | Vietnam, Socialist Republic Of (Thousand Dollars) | Japan (Thousand Dollars) | Hong Kong (Thousand Dollars) | Republic Of Korea (Thousand Dollars) | Taiwan (Thousand Dollars) | Macau (Thousand Dollars) | Mainland China (Thousand Dollars) | Afghanistan (Thousand Dollars) | Bangladesh (Thousand Dollars) | India (Thousand Dollars) | Maldives, Republic Of (Thousand Dollars) | Nepal (Thousand Dollars) | Pakistan (Thousand Dollars) | Sri Lanka (Thousand Dollars) | Bahrain (Thousand Dollars) | Cyprus (Thousand Dollars) | Iran (Islamic Republic Of) (Thousand Dollars) | Israel (Thousand Dollars) | Jordan (Thousand Dollars) | Kuwait (Thousand Dollars) | Lebanon (Thousand Dollars) | Oman (Thousand Dollars) | Qatar (Thousand Dollars) | Saudi Arabia (Thousand Dollars) | Syrian Arab Republic (Thousand Dollars) | United Arab Emirates (Thousand Dollars) | Yemen (Thousand Dollars) | Yemen Democratic (Thousand Dollars) | Canada (Thousand Dollars) | Puerto Rico (Thousand Dollars) | United States (Thousand Dollars) | Argentina (Thousand Dollars) | Brazil (Thousand Dollars) | Chile (Thousand Dollars) | Colombia (Thousand Dollars) | Ecuador (Thousand Dollars) | Mexico (Thousand Dollars) | Paraguay (Thousand Dollars) | Peru (Thousand Dollars) | Uruguay (Thousand Dollars) | Venezuela (Thousand Dollars) | Australia (Thousand Dollars) | Fiji (Thousand Dollars) | New Caledonia (Thousand Dollars) | New Zealand (Thousand Dollars) | Papua New Guinea (Thousand Dollars) | French Polynesia (Thousand Dollars) | Guam (Thousand Dollars) | Solomon Islands (Thousand Dollars) | Other Countries In Oceania (Thousand Dollars) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022 Dec | 55000084.0 | 6217.5 | 39734.8 | 4924.4 | 3034.8 | 1088.6 | 4137.1 | 432376.0 | 31084.0 | 402218.0 | 809343.0 | 131220.0 | 177243.0 | 128641.0 | 25910.0 | 1243341.0 | 360897.0 | 123349.0 | 46151.0 | 49367.0 | 71732.0 | 14099.0 | 311701.0 | 243227.0 | 0.0 | 47775.0 | 53076.0 | 683.0 | 7434.0 | 1248.0 | 4546.0 | 23443.0 | 1217.0 | 75900.0 | 3740306.0 | 5154779.0 | 1116549.0 | 1790423.0 | 449544.0 | 195030.0 | 4643.0 | 1958783.0 | 2271626.0 | 7403998.0 | 2865718.0 | 2768573.0 | 29319.0 | 6374198.0 | 214.0 | 294037.0 | 1703023.0 | 27931.0 | 18692.0 | 183923.0 | 134049.0 | 24163.0 | 48818.0 | 510.0 | 105746.0 | 15012.0 | 46086.0 | 1729.0 | 18234.0 | 64520.0 | 102899.0 | 260.0 | 625765.0 | 566.0 | 0.0 | 113586.0 | 4234.0 | 4671228.0 | 22119.0 | 227374.0 | 8570.0 | 12036.0 | 7249.0 | 224874.0 | 563.0 | 11791.0 | 3822.0 | 39.0 | 1711317.0 | 71371.0 | 32546.0 | 397788.0 | 84412.0 | 2428.0 | 41150.0 | 6018.0 | 691400.0 |
| 2022 Nov | 54162780.0 | 6394.2 | 37973.2 | 5025.2 | 3243.1 | 1527.0 | 4243.4 | 756814.0 | 29250.0 | 324451.0 | 927112.0 | 126740.0 | 33157.0 | 167460.0 | 4663.0 | 1190952.0 | 322583.0 | 74028.0 | 23462.0 | 40047.0 | 19921.0 | 18936.0 | 328426.0 | 245180.0 | 0.0 | 63588.0 | 63246.0 | 1005.0 | 2792.0 | 3033.0 | 6222.0 | 25261.0 | 2481.0 | 65457.0 | 4082822.0 | 5557119.0 | 1118234.0 | 1762557.0 | 392738.0 | 280992.0 | 2950.0 | 1568729.0 | 2504491.0 | 5302426.0 | 2165065.0 | 2667565.0 | 42902.0 | 6773005.0 | 272.0 | 339772.0 | 1467219.0 | 34754.0 | 12037.0 | 111265.0 | 133349.0 | 21034.0 | 57791.0 | 1091.0 | 122699.0 | 8410.0 | 44896.0 | 2798.0 | 16674.0 | 172041.0 | 106397.0 | 62.0 | 901306.0 | 1322.0 | 0.0 | 96999.0 | 56271.0 | 4787358.0 | 20687.0 | 170736.0 | 8683.0 | 13459.0 | 6212.0 | 277119.0 | 626.0 | 8651.0 | 947.0 | 482.0 | 1794035.0 | 55584.0 | 15556.0 | 573747.0 | 80267.0 | 17142.0 | 49396.0 | 7120.0 | 650476.0 |
| 2022 Oct | 56576348.0 | 6653.9 | 40500.8 | 5121.5 | 3114.5 | 1185.6 | 4298.1 | 350565.0 | 67327.0 | 529962.0 | 1035273.0 | 121392.0 | 117698.0 | 155578.0 | 6334.0 | 1189965.0 | 357153.0 | 81811.0 | 32247.0 | 60000.0 | 65311.0 | 21361.0 | 362032.0 | 220098.0 | 0.0 | 39889.0 | 47942.0 | 1321.0 | 7758.0 | 4156.0 | 5236.0 | 43738.0 | 11506.0 | 67063.0 | 4075989.0 | 6233818.0 | 1229078.0 | 1965567.0 | 461908.0 | 594395.0 | 7222.0 | 1730554.0 | 2406706.0 | 5137172.0 | 2330102.0 | 3034201.0 | 21959.0 | 7810503.0 | 345.0 | 465380.0 | 1395949.0 | 21845.0 | 13355.0 | 66674.0 | 93118.0 | 121596.0 | 62302.0 | 2586.0 | 78544.0 | 7316.0 | 40943.0 | 1148.0 | 45914.0 | 99750.0 | 242241.0 | 116.0 | 573275.0 | 700.0 | 0.0 | 110044.0 | 49109.0 | 5070780.0 | 23605.0 | 202358.0 | 7161.0 | 16109.0 | 6672.0 | 282600.0 | 987.0 | 7898.0 | 1885.0 | 676.0 | 1628700.0 | 70864.0 | 38811.0 | 499540.0 | 102466.0 | 34617.0 | 76617.0 | 7749.0 | 658085.0 |
| 2022 Sep | 62507132.0 | 7091.9 | 45605.1 | 5155.1 | 3453.3 | 1201.8 | 4065.4 | 386724.0 | 44793.0 | 358786.0 | 912066.0 | 150911.0 | 61522.0 | 125791.0 | 7283.0 | 1181847.0 | 379348.0 | 149219.0 | 35478.0 | 60601.0 | 45266.0 | 21764.0 | 579719.0 | 248160.0 | 0.0 | 60851.0 | 53511.0 | 2292.0 | 9914.0 | 2474.0 | 2679.0 | 40588.0 | 11752.0 | 81269.0 | 4373980.0 | 5884698.0 | 1367212.0 | 2241114.0 | 509268.0 | 1504662.0 | 27116.0 | 2375792.0 | 2481370.0 | 7405741.0 | 2896148.0 | 2875136.0 | 18310.0 | 7133642.0 | 453.0 | 547112.0 | 1817817.0 | 30156.0 | 15734.0 | 226902.0 | 191920.0 | 41003.0 | 64638.0 | 548.0 | 111282.0 | 7608.0 | 42895.0 | 1082.0 | 19112.0 | 95392.0 | 310368.0 | 85.0 | 813202.0 | 1464.0 | 0.0 | 134488.0 | 74606.0 | 5278523.0 | 52858.0 | 274320.0 | 44538.0 | 20157.0 | 11642.0 | 231403.0 | 1297.0 | 10393.0 | 969.0 | 64.0 | 1923247.0 | 89525.0 | 29359.0 | 528450.0 | 114715.0 | 2743.0 | 50413.0 | 9035.0 | 708359.0 |
| 2022 Aug | 63363749.0 | 7931.0 | 44106.2 | 6109.6 | 3608.4 | 1608.5 | 5020.5 | 570824.0 | 42761.0 | 454328.0 | 1291942.0 | 191678.0 | 68379.0 | 126344.0 | 9801.0 | 1512800.0 | 498657.0 | 100757.0 | 41036.0 | 36414.0 | 30590.0 | 18788.0 | 440859.0 | 229646.0 | 0.0 | 80433.0 | 48436.0 | 2590.0 | 4005.0 | 3363.0 | 2361.0 | 53328.0 | 8491.0 | 101311.0 | 4684693.0 | 6150507.0 | 1654932.0 | 2254888.0 | 455447.0 | 1087906.0 | 3719.0 | 2259090.0 | 2311824.0 | 6466344.0 | 2412712.0 | 2621213.0 | 26644.0 | 7548001.0 | 232.0 | 534857.0 | 1593916.0 | 32331.0 | 16029.0 | 132621.0 | 121017.0 | 48485.0 | 70390.0 | 810.0 | 138756.0 | 9380.0 | 34121.0 | 1380.0 | 68168.0 | 101056.0 | 119219.0 | 0.0 | 975155.0 | 1463.0 | 0.0 | 131512.0 | 32665.0 | 6094432.0 | 43246.0 | 258914.0 | 12651.0 | 17219.0 | 10004.0 | 258392.0 | 283.0 | 9050.0 | 2100.0 | 136.0 | 2060828.0 | 49089.0 | 39826.0 | 471479.0 | 75179.0 | 4153.0 | 73882.0 | 13854.0 | 823524.0 |
4 Visualizations
4.1 Uncover the Singapore Bi-lateral trend over Covid outbreak
We begin with a ribbon plot to illustrate the overall pattern of Singapore international trade over time. The function ggbraid helps distinguish between trade surplus and trade deficit by filling the region between two alternating lines with two different colors.
Step 1. Prepare data for line plot of Singapore
Code
singapore <- wide %>%
subset((Country == "Total Merchandise Imports"|Country == "Total Merchandise Exports")
& Level == "Country") %>%
group_by(MonthYear)
singaporeribbon <- singapore %>%
select(`Country`, `MonthYear`, `Level`, `ImportValue`, `ExportValue`) %>%
gather("Type", "Value", -`Country`, -`MonthYear`, -`Level`) %>%
drop_na()Step 2. Prepare data for line plot of Singapore
Code
p <- ggplot() +
geom_line(aes(`MonthYear`, `Value`, linetype = `Type`),
data = singaporeribbon,
show.legend = FALSE) +
labs(title = "Singapore Bi-lateral Trade Trend",
subtitle = "2016-2022",
x = 'Month Year',
y = 'Trade Value'
) +
annotate("segment",
x = as.Date("2020-01-01"),
xend = as.Date("2020-01-01"),
y = 0,
yend = 70000000,
colour = "red") +
annotate("text",
label = "Covid outbreak",
x = as.Date("2020-12-01"),
y=25000000,
color = "red")
p1 <- p+
geom_braid(aes(`MonthYear`,
ymin = `ImportValue`,
ymax = `ExportValue`,
fill = `ImportValue`>`ExportValue`),
show.legend = FALSE,
data = singapore,
alpha = 0.6,
method = 'line')
p1
ggplotly(p)
As a result of the COVID-19 epidemic, Singapore’s international commerce dropped in 2020
Singapore has a positive trade balance, or a trade surplus, according to the bilateral trend from 2016 to 2022. Prior to the start of the COVID-19 pandemic in 2020, Singapore’s international trade growth was robust from 2016 to 2019, but it began to weaken in 2019. Due to the outbreak of the COVID-19 pandemic in May 2020, the rate drops dramatically before quickly returning.
4.2 Merchandise trade performance with major trading partners
To illustrate the trade balance with all of Singapore’s trading partners, the bubble plot between import and export is chosen. The X-axis shows Singapore’s import value, while the Y-axis shows Singapore’s export value. Each bubble is colored differently depending on the country it represents.
The size of the bubbles indicates the total value of Singapore’s merchandise trade with the trading partner. If the bubble’s center point rises below the line, Singapore’s imports from the trade partner exceed Singapore’s exports. If the bubble’s center point falls beyond the line, Singapore’s exports to the trading partner exceed Singapore’s imports.
The graph is animated to emphasize the fluctuating equilibrium over time. Only major trading partners are depicted on the graph to reflect the effect of the key contributors.
Step 1. Create scatter plot with plotly
Code
# Plot scatter plot
scatter <- wide %>%
subset(Country == "China" | Country == "Malaysia" | Country == "Taiwan" | Country == "Hong Kong" | Country == "Indonesia" )
fig <- scatter %>%
plot_ly(
x = ~`ImportValue`,
y = ~`ExportValue`,
color = ~`Country`,
frame = ~as.character(`MonthYear`, format = "%Y-%m"),
size = ~`Total`,
sizes = c(1,10000),
text= ~paste("Country:",`Country`,
"\nImport Value:", `ImportValue`, " Thousand Dollars",
"\nExport Value:", `ExportValue`, " Thousand Dollars",
"\nTotal:", `Total`,
"\nMonth Year:", `MonthYear`),
hoverinfo = "text",
type = 'scatter',
mode = 'markers'
)Step 2. Set up layout
Code
# Create the diagonal line
dline <- function(color = "steelblue") {
list(
type = "line",
yref = "paper",
xref = "paper",
y0 = 0, y1 = 1,
x0 = 0, x1 = 1,
line = list(color = color, dash="dot")
)
}
# Setup layout
fig <- fig %>%
layout(title = list(text="MERCHANDISE TRADE PERFORMANCE WITH MAJOR TRADING PARTNERS"),
subtitle = "2016-2022",
hoverlabel = list(align = "left"),
shapes = dline(),
legend = list(orientation = "h", y = 1, x = 0),
showlegend = FALSE,
xaxis = list(title="Import Value", range = list(0, 10000000)),
yaxis = list(title="Export Value", range = list(0, 10000000)),
width=650,
height=650
)Step 3. Set up animation
Code
fig <- fig %>%
animation_opts(
500, easing = "linear", redraw = FALSE
)
# Animation slider
fig <- fig %>% animation_slider(
currentvalue = list(prefix = "MONTH-YEAR :", font = list(color="red"))
)
figChina’s import and export volume declined sharply in the beginning of 2020
China bubble declines along the diagonal from December 2019 until February 2020. This implies a significant decline in both imports and exports from China within the specified time frame. But, it returned shortly thereafter.
With a similar trajectory to China, the bubble of Malaysia in December 2019 proceeded diagonally downward. Yet, it continued to decline until mid-2020.
In May of 2020, the impact of Indonesia is clearly seen by a 25% decline in overall volume.
Unlike exports to other partners, Singapore’s exports to Hong Kong do not appear to be as affected. However, a faster increase in exports to Hong Kong is observed in 2021.
We employ the ribbon chart once again to assess the impact of Covid-19 on Singapore’s most major trading partners.
Code
hues <- scales::hue_pal()(2)
braid <- wide %>%
select(`Country`, `MonthYear`, `Level`, `ImportValue`, `ExportValue`) %>%
drop_na() %>%
subset(Country == "China")
ribbon <- gather(braid , "Type", "Value", -`Country`, -`MonthYear`, -`Level`)
braid2 <- wide %>%
select(`Country`, `MonthYear`, `Level`, `ImportValue`, `ExportValue`) %>%
drop_na() %>%
subset(Country == "Malaysia")
ribbon2 <- gather(braid2 , "Type", "Value", -`Country`, -`MonthYear`, -`Level`)
braid3 <- wide %>%
select(`Country`, `MonthYear`, `Level`, `ImportValue`, `ExportValue`) %>%
drop_na() %>%
subset(Country == "Taiwan")
ribbon3 <- gather(braid3 , "Type", "Value", -`Country`, -`MonthYear`, -`Level`)
braid4 <- wide %>%
select(`Country`, `MonthYear`, `Level`, `ImportValue`, `ExportValue`) %>%
drop_na() %>%
subset(Country == "Hong Kong")
ribbon4 <- gather(braid4 , "Type", "Value", -`Country`, -`MonthYear`, -`Level`)
braid5 <- wide %>%
select(`Country`, `MonthYear`, `Level`, `ImportValue`, `ExportValue`) %>%
drop_na() %>%
subset(Country == "Indonesia")
ribbon5 <- gather(braid5 , "Type", "Value", -`Country`, -`MonthYear`, -`Level`)
ggplot() +
geom_line(aes(`MonthYear`, `Value`, linetype = `Type`),
data = ribbon,
show.legend = FALSE) +
geom_braid(aes(`MonthYear`,
ymin = `ImportValue`,
ymax = `ExportValue`,
fill = `ImportValue`>`ExportValue`),
data = braid,
alpha = 0.6,
method = 'line',
show.legend = FALSE)+
labs(title = "Singapore trade balance trend with China",
x = 'Month Year',
y = 'Trade Value'
) +
annotate("rect",
xmin = as.Date("2020-01-01"),
xmax = as.Date("2022-12-01"),
ymin = 0,
ymax = 10000000,
alpha = .1,
fill = "yellow")
ggplot() +
geom_line(aes(`MonthYear`, `Value`, linetype = `Type`),
data = ribbon2,
show.legend = FALSE) +
geom_braid(aes(`MonthYear`,
ymin = `ImportValue`,
ymax = `ExportValue`,
fill = `ImportValue`>`ExportValue`),
data = braid2,
alpha = 0.6,
method = 'line',
show.legend = FALSE)+
labs(title = "Singapore trade balance trend with Malaysia",
x = 'Month Year',
y = 'Trade Value'
) +
annotate("rect",
xmin = as.Date("2020-01-01"),
xmax = as.Date("2022-12-01"),
ymin = 0,
ymax = 10000000,
alpha = .1,
fill = "yellow")+
annotate("text",
x = as.Date("2021-01-01"),
y = 2500000, size = 4,
label = "Import > Export",
hjust = 0,
color = hues[2])
ggplot() +
geom_line(aes(`MonthYear`, `Value`, linetype = `Type`),
data = ribbon3,
show.legend = FALSE) +
geom_braid(aes(`MonthYear`,
ymin = `ImportValue`,
ymax = `ExportValue`,
fill = `ImportValue`<`ExportValue`),
data = braid3,
alpha = 0.6,
method = 'line',
show.legend = FALSE)+
labs(title = "Singapore trade balance trend with Taiwan",
x = 'Month Year',
y = 'Trade Value'
) +
annotate("rect",
xmin = as.Date("2020-01-01"),
xmax = as.Date("2022-12-01"),
ymin = 0,
ymax = 10000000,
alpha = .1,
fill = "yellow")+
annotate("text",
x = as.Date("2019-01-01"),
y = 1000000, size = 4,
label = "Import > Export",
hjust = 0,
color = hues[2])
ggplot() +
geom_line(aes(`MonthYear`, `Value`, linetype = `Type`),
data = ribbon4,
show.legend = FALSE) +
geom_braid(aes(`MonthYear`,
ymin = `ImportValue`,
ymax = `ExportValue`,
fill = `ImportValue`>`ExportValue`),
data = braid4,
alpha = 0.6,
method = 'line',
show.legend = FALSE)+
labs(title = "Singapore trade balance trend with Hong Kong",
x = 'Month Year',
y = 'Trade Value'
) +
annotate("rect",
xmin = as.Date("2020-01-01"),
xmax = as.Date("2022-12-01"),
ymin = 0,
ymax = 10000000,
alpha = .1,
fill = "yellow")+
annotate("text",
x = as.Date("2019-01-01"),
y = 9000000, size = 4,
label = "Export > Import",
hjust = 0,
color = hues[1])
ggplot() +
geom_line(aes(`MonthYear`, `Value`, linetype = `Type`),
data = ribbon5,
show.legend = FALSE) +
geom_braid(aes(`MonthYear`,
ymin = `ImportValue`,
ymax = `ExportValue`,
fill = `ImportValue`>`ExportValue`),
data = braid5,
alpha = 0.6,
method = 'line',
show.legend = FALSE)+
labs(title = "Singapore trade balance trend with Indonesia",
x = 'Month Year',
y = 'Trade Value'
) +
annotate("rect",
xmin = as.Date("2020-01-01"),
xmax = as.Date("2022-12-01"),
ymin = 0,
ymax = 10000000,
alpha = .1,
fill = "yellow")+
annotate("text",
x = as.Date("2019-01-01"),
y = 9000000, size = 4,
label = "Export > Import",
hjust = 0,
color = hues[1])




Singapore Bi-lateral trend with major trading partners
The ribbon chart conveys the same message as the bubble chart. In February 2020, a significant decline in imports and exports between Singapore and China could be recognized. In terms of import and export rates, trade between Singapore and China has been well balanced. In 2021, Singapore will likely export more to China.
Malaysia demonstrates an unexpected tendency. Prior to the start of Covid-19, commerce between Singapore and Malaysia was balanced. Since the Covid-19 outbreak, however, Singapore has had a trade deficit with Malaysia.
Covid-19 appears to have little effect on Singapore imports from Taiwan. Taiwan’s import volume keeps on growing steadily.
Export from Singapore to Hong Kong has a minimal effect, as there is no discernible change in trend, but the export rate is projected to rise in 2021.
Imports and exports with Indonesia decreased significantly at the beginning of 2020.
4.3 Observe trade dynamic of Singapore’s major trading partners in relative
The slope graph allows us to see how each country’s import and export dynamics change in relation to the other countries over time.
Step 1. Prepare data for slope graph
Code
# Import
slopeimport <- wide %>%
subset(Country == "China" | Country == "Malaysia" | Country == "Taiwan" | Country == "Hong Kong" | Country == "Indonesia" ) %>%
mutate(month = month(MonthYear)) %>%
mutate(year = year(MonthYear)) %>%
drop_na() %>%
group_by(Country, year) %>%
summarise(sumyear = sum(ImportValue)) %>%
mutate(Year = factor(year)) %>%
arrange(`sumyear`)
#Export
slopeexport <- wide %>%
subset(Country == "China" | Country == "Malaysia" | Country == "Taiwan" | Country == "Hong Kong" | Country == "Indonesia" ) %>%
mutate(month = month(MonthYear)) %>%
mutate(year = year(MonthYear)) %>%
drop_na() %>%
group_by(Country, year) %>%
summarise(sumyear = sum(ExportValue)) %>%
mutate(Year = factor(year)) %>%
arrange(`sumyear`)Step 2. Create slope plot
Code
# Create slope plot for import
p <- newggslopegraph(dataframe = slopeimport,
Times = `Year`,
Measurement = `sumyear`,
Grouping = `Country`,
Title = "Total Import per Year",
SubTitle = "2016-2022",
Caption = NULL)
p + annotate("rect",
xmin = "2020",
xmax = "2022",
ymin = -1,
ymax = 600000,
alpha = .1,
fill = "yellow")
# Create slope plot for export
p2 <- newggslopegraph(dataframe = slopeexport,
Times = `Year`,
Measurement = `sumyear`,
Grouping = `Country`,
Title = "Total Export per Year",
SubTitle = "2016-2022",
Caption = NULL)
p2 + annotate("rect",
xmin = "2020",
xmax = "2022",
ymin = -1,
ymax = 600000,
alpha = .1,
fill = "yellow")

Trade dynamic of Singapore’s major trading partners in relative
There is no change in rank for import. China has consistently ranked #1 in terms of imports. Singapore has expanded its imports from three nations, including China, Malaysia, and Taiwan, beginning in 2020.
Likewise, there is no change in rank on the export side. China has continuously topped the exporting rankings. Similar to Hong Kong, although China’s export rate slowed in 2019, growth accelerated in 2021. Malaysia and Indonesia’s export volumes dropped drastically in 2020 before rebounding in 2021.
4.4 Observing the dynamic of trade balance based on location
Step 1. Prepare data for Choropleth map
Code
data("World")
map <- World %>%
select(iso_a3, name, sovereignt, geometry)
map$name <- as.character(map$name)
map$sovereignt <- as.character(map$sovereignt)Step 2. Create animated map
Code
data_map_area <- map %>%
full_join(wide, by = c('sovereignt' = 'Country')) %>%
drop_na()
tmap_mode("view")
choropleth <- tm_shape(data_map_area) +
tm_polygons("Diff") +
tm_facets(along = "MonthYear", free.coords = FALSE)
tmap_animation(choropleth , filename = "choropleth.gif", delay = 50)
4.5 Monitoring the relative trade balance dynamics of Singapore’s major trading partners
Heatmaps allow us to see the group’s auto-correlation and compare it to another group at the same time.
Step 1. Prepare data by selecting top difference between import and export
Code
heatmap <- wide %>%
drop_na() %>%
group_by(Country) %>%
mutate(totaldiff = sum(Diff)) %>%
arrange(totaldiff) %>%
subset(Country == "China" | Country == "Malaysia" | Country == "Taiwan" | Country == "Hong Kong" | Country == "Indonesia" ) Step 2. Plot heatmap
Code
p <- heatmap %>%
ggplot(aes(x = MonthYear, y = reorder(Country,totaldiff), fill= Diff)) +
geom_tile_interactive(tooltip = c(paste( "Country:", heatmap$Country,
"\n Import:", heatmap$ImportValue,
"\n Export:", heatmap$ExportValue,
"\n Balance:" , -heatmap$Diff,
"\n Month:", heatmap$MonthYear))) +
scale_fill_distiller(palette = "Spectral") +
theme_ipsum() +
geom_tile() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=2))+
labs(title = "Relative trade balance dynamics of Singapore's major trading partners", x="", y="") +
annotate("segment",
x = as.Date("2020-01-01"),
xend = as.Date("2020-01-01"),
y = 0,
yend = 6,
colour = "red") +
annotate("text",
label = "Covid outbreak",
x = as.Date("2020-06-01"),
y=2,
color = "red")
girafe(
ggobj = p,
width_svg = 15,
height_svg = 3
)Insights from heatmap
The difference in color tone between Hong Kong and the other countries stand out as the trading relationship between Singapore and Hong Kong is highly surplus. The darker blue color of Hong Kong, which began in early 2021, reflects the quicker rise of export volume in comparison to import volume.
Contrary to Hong Kong, Taiwan reflects the outstanding deficit balance. The gradual darkening of the red shade over time for Taiwan represents the continuing increase of import volume over export.
4.6 Singapore-China trading pattern
Step 1: Deriving month and year fields
Code
cycle <- wide
cycle$month <- month(cycle$`MonthYear`)
cycle$year <- year(cycle$`MonthYear`)Step 2: Extracting the target country
Code
cycle <- cycle %>%
subset(`Country`== "China") %>%
drop_na()Step 3: Plotting the cycle plot
Code
ggplot() +
geom_line(data=cycle, aes(x=year, y=ImportValue, group=month), colour= "steelblue") +
geom_line(data=cycle, aes(x=year, y=ExportValue, group=month), colour= "#ec5954") +
facet_grid(~month) +
labs(title = "Singapore-China trading pattern",
subtitle = "2016-2022") +
ylab("Trading Volume") +
theme(plot.title = element_text(size=15),
axis.text.x = element_text(size = 10, angle = 90),
axis.text.y = element_text(size = 10),
strip.text = element_text(size = 10))
Singapore-China trade
From the cycle plot, we note that each month follows a similar pattern, with a dip in 2019-2020 and a rise beginning in 2021.
5 Interactive Dashboard
An interactive dashboard has been created to assist users in determining the impact of Covid-19 on Singapore bi-lateral commerce. The dashboard includes user-selected country and month input for time specification.
Code
# Prepare data for dashboard
line <- long %>%
subset(Type == "ImportValue"|Type == "ExportValue")
# Building interactive filters
d <- highlight_key(line)
filter_tools <- htmltools::div(
filter_select(id = "filter",
label = "Select Country",
sharedData = d,
group = ~Country,
multiple=FALSE),
filter_slider(id = "period",
label = "Select period",
sharedData = d,
column = ~year(MonthYear),
width = "100%"),
filter_slider(id = "value",
label = "Select Value",
sharedData = d,
column = ~Value,
width = "100%"),
filter_checkbox(id = "variable",
label = "Select variable",
sharedData = d,
group = ~Type,
inline = FALSE))
vline <- function(x = 0, color = "steelblue") {
list(
type = "line",
y0 = 0, y1 = 1,
yref = "paper",
x0 = x, x1 = x,
line = list(color = color, dash="dot")
)
}
# plotting interactive scatter plot using plotly
p <- plot_ly(data=d,
type= "scatter",
mode= "line",
x= ~MonthYear,
y= ~Value,
color= ~Type,
colors= "Accent",
# fill = 'tonexty',
text= ~paste("Country:",`Country`,
"\nMonth Year:", `MonthYear`,
"\nType:",`Type`)) %>%
layout(title = list(text="<b>Import/Export trend by country</b>"),
hoverlabel = list(align = "left"),
legend = list(orientation = "h", y = 1, x = 0),
shapes = vline("2020"),
xaxis = list(title="Month Year"),
yaxis = list(title="Value"))
gg <- highlight(p, "plotly_selected")
# Using crosstalk bscols to put all 3 elements (filter, scatter plot, datatable) together.
crosstalk::bscols(filter_tools,gg,DT::datatable(d, class= "display",
filter=list(position="top", clear=FALSE),
options=list(pageLength = 10,scrollY = TRUE,
iDisplayLength = 25)),
widths = c(4, 8, 12),
annotations = list(caption = "Data from Department of Statistics, Singapore (DOS)"))Code
function filter_default() {
document.getElementById("filter").getElementsByClassName("selectized")
[0].selectize.setValue("China", false);
}
window.onload = filter_default;6 Conclusion
Covid-19 has had a tremendous impact on the international trade of Singapore. For each country, the impact occurs at a different period and with a distinct magnitude. In 2021, the pattern, however, returned to steady growth.
Code
# Building interactive filters
# d <- highlight_key(ribbon)
# # d2 <- highlight_key(braid)
#
# filter_tools <- htmltools::div(
# filter_select(id = "country",
# label = "Select Country",
# sharedData = d,
# group = ~Country,
# multiple=FALSE),
#
# filter_slider(id = "period",
# label = "Select period",
# sharedData = d,
# column = ~year(MonthYear),
# width = "100%"))
#
# # plotting interactive scatter plot using plotly
# p <- ggplot() +
# geom_line(aes(`MonthYear`, `Value`, linetype = `Type`), data = ribbon)
# # +
# # geom_braid(aes(`MonthYear`,
# # ymin = `ImportValue`,
# # ymax = `ExportValue`,
# # fill = `ImportValue`>`ExportValue`),
# # data = braid, alpha = 0.6) +
# # guides(linetype = "none", fill = "none")
#
#
# gg <- highlight(p, "plotly_selected")
#
# # Using crosstalk bscols to put all 3 elements (filter, scatter plot, datatable) together.
# crosstalk::bscols(filter_tools, gg, widths = c(4, 8))